home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10711 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: inforamp.net!ts10-07
  2. From: rmorin@inforamp.net (Randy Charles Morin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Question about visibility of local variables
  5. Date: Sat, 09 Mar 96 18:00:36 GMT
  6. Organization: MiddleWorld SoftWare
  7. Message-ID: <4hsh0g$pmm@sam.inforamp.net>
  8. References: <4hgufv$48h@hpbblb.bbn.hp.com> <4hifc6$hm5@news1.usa.pipeline.com> <4hj56k$elu@sam.inforamp.net> <313E7807.5CC2@parashift.com>
  9. NNTP-Posting-Host: ts10-07.tor.inforamp.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <313E7807.5CC2@parashift.com>,
  13.    Mike Girou <girou@parashift.com> wrote:
  14. >Well, maybe.  Certainly that was the way we did things in C.  But
  15. >there has been quite a lot written about declaring/defining at first
  16. >use, particularly with class variables.  These arguments include
  17. >possible efficiency and the notion that variables needed to properly
  18. >initialize may not be known when the "block" is entered.
  19.  
  20. I agree completely.  Sometimes, it is better to declare the variable later on 
  21. in a block.  But it is much more efficient to add blocks.
  22.  
  23. Example:
  24.  
  25. {
  26.     BIGCHUNKOFMEMORY a,b,c;
  27.     ...
  28.     a=
  29.     ...
  30.     b=
  31.     ...
  32.     c=
  33.     ...
  34. }
  35.  
  36. ..could also be ...
  37.  
  38. {
  39.     ...
  40.     BIGCHUNKOFMEMORY a=
  41.     ...
  42.     BIGCHUNKOFMEMORY b=
  43.     ...
  44.     BIGCHUNKOFMEMORY c=
  45.     ...
  46. }
  47.  
  48. ..but this is also inefficient.
  49.  
  50. Instead of declaring stuff half way through a block,
  51. it is better to add blocks...
  52.  
  53. {
  54.     ...
  55.     {
  56.         BIGCHUNKOFMEMORY a=
  57.         ...
  58.     }
  59.     {
  60.         BIGCHUNKOFMEMORY b=
  61.         ...
  62.     }
  63.     {
  64.         BIGCHUNKOFMEMORY c=
  65.         ...
  66.     }
  67. }
  68.  
  69. This is much more efficient then the previous and it is easier to read a block 
  70. since the variables will be declared at the beginning of the block.
  71.  
  72. Agrivar
  73.